import hasPermi from './hasPermi.js';
import User from '@/store/user.js';
import Dict from '@/store/dict.js';
import Com from '@/store/com.js';
import {
	pickerDefault,
	selectDictLabel
} from "./autoImport.js"

export default {
	install(App) {
		uni['$store'] = App.config.globalProperties.$store = {
			user: User(),
			dict: Dict(),
			com: Com()
		};

		uni['hasPermi'] = App.config.globalProperties.hasPermi = (value) => {
			if (value && value instanceof Array && value.length > 0) {
				return value.some((permission) => uni.$store.user.roleList.includes(permission));
			} else {
				return true
				// 	throw new Error(`请设置操作权限标签值`);
			}
		}

		App.config.globalProperties.pickerDefault = pickerDefault
		App.config.globalProperties.selectDictLabel = selectDictLabel

		/**
		 * vite动态加载图片静态文件
		 * @param {string} path 文件路径
		 * @returns
		 */
		const modules = import.meta.glob('../static/img/**/*', {
			eager: true
		});
		App.config.globalProperties.getImgUrl = (path) => {
			if (path && modules) {
				if (path.includes('../static/img/')) {
					return modules[path]?.default;
				} else {
					return modules[`../static/img/${path}`]?.default;
				}
			}
		};
	},
};